4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
11 // You must not remove this notice, or any other, from this software.
16 // This tool scans through pal_error.h (must be in the current directory
17 // and finds all "#define ERROR_" lines. For each of those, it calls
18 // Win32 FormatMessageW to find the error text, and produces a
19 // rotor_pal.satellite file containing the error text. This satellite file
20 // can be used by the PAL on non-Win32 platforms.
22 #include <rotor_palrt.h>
24 #define DEFINE_PREFIX "#define "
26 #define STARTTAG "/* STARTERRORCODES" // comment
27 #define ENDTAG "/* ENDERRORCODES" // comment
30 WCHAR ErrorText
[4096];
32 int __cdecl
main(int argc
, char *argv
[]) {
38 fpIn
= fopen("pal_error.h", "r");
41 "Unable to open pal_error.h for read\n");
45 fpOut
= fopen("rotor_pal.rc", "w");
48 "Unable to open rotor_pal.satellite for write\n");
52 fprintf(fpOut
, "// ==++==\n");
53 fprintf(fpOut
, "//\n");
54 fprintf(fpOut
, "// Copyright (c) Microsoft Corporation. All rights reserved.\n");
55 fprintf(fpOut
, "//\n");
56 fprintf(fpOut
, "// ==--==\n");
58 fprintf(fpOut
, "\n// This file is autogenerated by the palsatellite tool from pal_error.h\n");
60 fprintf(fpOut
, "\n#pragma code_page(65001)\n"); // UTF-8
62 fprintf(fpOut
, "\nSTRINGTABLE\nBEGIN\n");
73 fgets(Line
, sizeof(Line
), fpIn
);
76 if (strncmp(Line
, STARTTAG
, sizeof(STARTTAG
)-1) == 0)
80 if (strncmp(Line
, ENDTAG
, sizeof(ENDTAG
)-1) == 0)
85 // Line is not in the error codes block
89 if (strncmp(Line
, DEFINE_PREFIX
, sizeof(DEFINE_PREFIX
)-1)) {
90 // Line doesn't start with "#define "
94 p
= strchr(Line
+sizeof(DEFINE_PREFIX
), ' ');
96 // Line isn't "#define xxxx yyyy"
101 if (Value
< 0 || Value
> 65536) {
103 "Win32 error value out of range at line %d\n", LineNum
);
107 dw
= FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
|
108 FORMAT_MESSAGE_IGNORE_INSERTS
,
111 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
113 sizeof(ErrorText
)/sizeof(WCHAR
),
117 "FormatMessageW failed at line %d, Error=%d, LastError=%d\n",
123 i
= WideCharToMultiByte(CP_UTF8
,
133 "WCtoMB failed at line %d, LastError=%d\n",
139 fprintf(fpOut
, "%d \"", Value
);
145 // ignore Windows end of lines - the satellite file is meant to be used on Unix
148 fprintf(fpOut
, "\\n");
151 fprintf(fpOut
, "\\\"");
154 fprintf(fpOut
, "\\\\");
163 fprintf(fpOut
,"\"\n");
166 fprintf(fpOut
, "END\n");